package com.example.myapplication4;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class MyAdpapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<String> datas;
    private LayoutInflater inflater;

    public MyAdpapter(Context mContext,List<String> datas){
        this.datas = datas;
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View mView = inflater.inflate(R.layout.my_item,parent,false);
        myViewHolder myViewHolder = new myViewHolder(mView);
        Log.i("onCreateViewHolder",viewType+"");
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        myViewHolder myViewHolder= (MyAdpapter.myViewHolder) holder;
        myViewHolder.textView.setText(datas.get(position)+"测试");
        myViewHolder.textView.setBackgroundColor(Color.RED);
        Log.i("onBindViewHolder",datas.get(position));
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    public class myViewHolder extends RecyclerView.ViewHolder{

        private TextView textView;
        public myViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.textview);
        }
    }
}
